package org.tgcms.core.dal.appengine.domain;

import java.util.List;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Version;
import javax.jdo.annotations.VersionStrategy;

import org.tgcms.core.dal.dto.Website;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Text;

@PersistenceCapable
@Version(strategy = VersionStrategy.VERSION_NUMBER, column = "version", extensions = { @Extension(vendorName = "datanucleus", key = "field-name", value = "version") })
public class AppengineWebsite implements AppengineEntity, Website {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	private Long version;

	@Persistent
	private String name;

	@Persistent
	private List<String> urls;

	@Persistent
	private Text comment;

	public AppengineWebsite() {
	}

	public AppengineWebsite(Website website) {
		this.name = website.getName();
		this.urls = website.getUrls();
		if (website.getComment() != null) {
			this.comment = new Text(website.getComment());
		}
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public Long getVersion() {
		return version;
	}

	public void setVersion(Long version) {
		this.version = version;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<String> getUrls() {
		return urls;
	}

	public void setUrls(List<String> urls) {
		this.urls = urls;
	}

	public String getComment() {
		return (comment == null) ? null : comment.getValue();
	}

	public void setComment(String comment) {
		this.comment = new Text(comment);
	}

}
